/**
 * Created by 魏爷 on 2016/5/8.
 */
$(function(){
    var url=$('#add-url').val();
    var url_dis=$('#dis-url').val();
    var url_rec=$('#rec-url').val();
    var url_del=$('#del-url').val();
    var app={
        add:function(obj){
            var loading=layer.load(1);
            $.post(
                url,
                {u_type_name:$('#u_type_name').val(),u_book_borrow:$('#u_book_borrow').val()},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        disable:function(obj){
            var loading=layer.load(1);
            $.post(
                url_dis,
                {u_type_id:obj.attr('data-id-dis')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        recover:function(obj){
            var loading=layer.load(1);
            $.post(
                url_rec,
                {u_type_id:obj.attr('data-id-rec')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        delete:function(obj){
            var loading=layer.load(1);
            $.post(
                url_del,
                {u_type_id:obj.attr('data-id-del')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

    }
    $('.add').click(function () {
        app.add($(this));
    });
    $('.dis').click(function () {
        app.disable($(this));
    });
    $('.rec').click(function () {
        app.recover($(this));
    });
    $('.del').click(function () {
        app.delete($(this));
    });
});